﻿using Python.Runtime;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cs2py
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.ThreadException += Application_ThreadException;
            var f = new PynetForm();
            //f.ShowDialog();

            Application.Run(f);
            //UsePythonnet.Init();
            //UsePythonnet.Run();
            //UsePythonnet.Shutdown();

            //UseIronPython.Run();
            //Console.ReadLine();
        }

        private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            var obj = e.Exception;
            var msg = $"{obj.Message}\n{obj.StackTrace}\n{obj.Source}";
            var sstr = sender.ToString();
            MessageBox.Show(msg + "\n" + sstr, "错误 APP");
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            if (e.ExceptionObject != null)
            {
                var obj = e.ExceptionObject as Exception;
                var msg = $"{obj.Message}\n{obj.StackTrace}\n{obj.Source}";
                var sstr = sender.ToString();
                MessageBox.Show(msg + "\n" + sstr, "错误 Domain");
            }
            else
            {
                var sstr = sender.ToString();
                MessageBox.Show(sstr, "错误 Domain");
            }
        }
    }
}
